{layout name="layout" /}

<div class="Hui-article">
	<article class="cl pd-20" style="min-width:700px; max-width:70%;">
		<div class="cl pd-5 bg-1 bk-gray">
			<span class="l">
				<a href="javascript:;" onclick="del_all()" class="btn btn-danger radius">
					<i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
				<a class="btn btn-primary radius" href="{:url('add')}">
					<i class="Hui-iconfont">&#xe600;</i> 添加权限</a>
			</span>
			<!-- <span class="r">共有数据：<strong>54</strong> 条</span>  -->
		</div>
		<div class="mt-10">
			<table class="table table-border table-bordered table-hover table-bg">
				<thead>
					<tr>
						<th scope="col" colspan="7">权限管理</th>
					</tr>
					<tr class="text-c">
						<th width="25px">
							<input type="checkbox" value="" name="">
						</th>
						<th width="60px">ID</th>
						<th width="160px">权限名称</th>
						<th width="160px">控制器或方法(小写)</th>
						<th width="80px">状态</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					{foreach $data as $value}
					<tr class="text-c">
						<td>
							<input type="checkbox" value="{$value.id}" name="checkbox[]">
						</td>
						<td>
							<a href="javascript:void(0);" style="text-decoration: none;" onclick="loadchild(this, '{$value.id}')" data-stat="0">
								<i class="Hui-iconfont" style="font-size: 16px;">&#xe604;</i> {$value.id}
							</a>
						</td>
						<td>{$value.name}</td>
						<td>{$value.method}</td>
						<td>{eq name="value.status" value="1"}
							<a href="javascript:void(0);" title="停用" onClick="down('down',this,'{$value.id}')" style="text-decoration:none">
								<span class="label label-success radius">启用</span>
							</a>
							{else/}
							<a href="javascript:void(0);" title="启用" onClick="down('up',this,'{$value.id}')" style="text-decoration:none">
								<span class="label label-default radius">停用</span>
							</a>
							{/eq}
						</td>
						<td class="f-14">
							<a title="编辑" href="{:url('edit','id='.$value.id)}" style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6df;</i>
							</a>
							<a title="删除" href="javascript:;" onclick="del(this,'{$value.id}')" class="ml-5" style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6e2;</i>
							</a>
						</td>
					</tr>
					{notempty name="value.child"} {foreach $value.child as $val}
					<tr class="text-c child_{$value.id}" style="display: none;">
						<td>
							<input type="checkbox" value="{$val.id}" name="checkbox[]">
						</td>
						<td>&nbsp;&nbsp;&nbsp;└─ {$val.id}</td>
						<td>{$val.name}</td>
						<td>{$val.method}</td>
						<td>{eq name="val.status" value="1"}
							<a href="javascript:void(0);" title="停用" onClick="down('down',this,'{$val.id}')" style="text-decoration:none">
								<span class="label label-success radius">启用</span>
							</a>
							{else/}
							<a href="javascript:void(0);" title="启用" onClick="down('up',this,'{$val.id}')" style="text-decoration:none">
								<span class="label label-default radius">停用</span>
							</a>
							{/eq}
						</td>
						<td class="f-14">
							<a title="编辑" href="{:url('edit','id='.$val.id)}" style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6df;</i>
							</a>
							<a title="删除" href="javascript:;" onclick="del(this,'{$val.id}')" class="ml-5" style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6e2;</i>
							</a>
						</td>
					</tr>
					{/foreach} {/notempty} {/foreach}
				</tbody>
			</table>
		</div>
	</article>
</div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
	function loadchild(obj, id){
		var stat = $(obj).data('stat');
		console.log(obj);
		console.log(id);
		console.log(stat);
		
		if (stat ==1) {
			$(".child_"+id).css("display", "none");
			$(obj).children('i').html('&#xe604;');
			$(obj).data('stat', 0);
			return false;
		}
		$(".child_"+id).css('display', '');
		$(obj).children('i').html('&#xe631;');
		$(obj).data('stat', 1);
	}

	function down(action, obj, id) {
		var duty = 2,
			title = '启用',
			button = 'default',
			status = '停用';

		if (action == 'up') {
			duty = 1;
			title = '停用';
			status = '启用';
			button = 'success';
			action = 'down';
		} else {
			action = 'up';
		}


		var text = "<a href=\"javascript:void(0);\" title=" + title + " onClick=\"down('" + action + "', this," + id +
			")\" >";
		text += '<span class="label label-' + button + ' radius">' + status + '</span></a>';

		$.post("duty", {
			'id': id,
			'status': duty
		}, function (data) {
			if (data.code == 2) {
				layer.msg(data.msg, {
					icon: 6,
					time: 1000
				});
				$(obj).after(text);
				$(obj).remove();
			} else {
				layer.msg(data.msg, {
					icon: 5,
					time: 1000
				});
			}
		}, 'json');
	}
</script>
<!--请在上方写此页面业务相关的脚本-->